import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-07-25
 * Time: 13:53
 */
public class CardDemo {
    public static final  String[] suits = {"♣","♠","♥","♦"};
    //买一副牌
    public List<Card> buyCard() {
        List<Card> cardList = new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                int rank = i;
                String suit = suits[j];
                Card card = new Card(rank,suit);
                cardList.add(card);
            }
        }
        return cardList;
    }
    
    //洗牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);

        }
    }
    private void swap(List<Card> cardList,int i,int index) {
        Card tmp = cardList.get(i);
        cardList.set(i,cardList.get(index));
        cardList.set(index,tmp);
    }

    //3个人，每人轮流摸5张
    public List<List<Card>> play(List<Card> cardList) {
        List<List<Card>> list = new ArrayList<>();
        List<Card> list0 = new ArrayList<>();
        List<Card> list1 = new ArrayList<>();
        List<Card> list2 = new ArrayList<>();
        list.add(list0);
        list.add(list1);
        list.add(list2);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                //怎么把牌放到对应的人手中
                list.get(j).add(card);
            }
        }
        return list;
    }
}
